package com.z1.core.utils;

public class UserConst {

	public static void main(String args[]) {
//		System.out.println("123q!@#".matches(passwordRegex));
	}
	public static final int success = 0;
	
	public static final int minPasswordLength = 8;
	
	//字母、数字、特殊字符同时存在
	public static final String passwordRegex = "^(?![a-zA-Z0-9]+$)(?![^a-zA-Z/D]+$)(?![^0-9/D]+$).{8,20}$";
	
	//警员身份
	public static final Integer IdentityPolice = 1;
	
	//非警员身份
	public static final Integer IdentityNotPolice = 0;
	
	public static final Integer allowedNormalUserAceess = 1;
	
	//密码长度过短错误
	public static final int passwordLengthError = 0x101;
	
	//密码安全系数低
	public static final int passwordNotSafeError = 0x102;
	
	//两次输入密码不一致
	public static final int passwordNotEqualError = 0x103;
	
	//修改密码时旧密码验证失败
	public static final int oldPasswordFailedError = 0x104;
	
	//身份证校验成功
	public static final int idcardCheckSuccess = 0;
	
	//身份证长度错误
	public static final int idcardLengthError = 0x201;
	
	//身份证校验区位码错误
	public static final int idcardCheckBitError = 0x202;
	
	//身份证校验生日错误
	public static final int idcardBirthdayError = 0x203;
	
	//身份证校验最后一位错误
	public static final int idcardLastBitError = 0x204;
	
	//用户名唯一性错误
	public static final int usernameDuplicateError = 0x301;
	
	//员工编号唯一性错误
	public static final int employerIdDuplicateError = 0x302;
	
	//身份证好唯一性错误
	public static final int idcardDuplicateError = 0x303;
	
	//需要强制修改密码
	public static final int needForceChangePwd = 1;
	
	//不需要强制修改密码
	public static final int notNeedForceChangePwd = 0;
	
	public static final int userLockType_NotLock = 0;
	
	public static final int userLockType_Lock = 1;
	
	//由于用户有效期截至而被锁定
	public static final int userLockType_InvalidLock = 2;
	
	//由于用户鉴权次数失败过多导致锁定
	public static final int userLockType_FailedAuthLock = 3;
	
	//由于有人后台人为修改了允许连续登录次数的数据表而导致的锁定
	public static final int userLockType_LoginPolicyTableErrorLock = 4;
	
	//用户长期未使用导致被锁定 
	public static final int userLongTimeNotUseLock = 5;
	
	//用户被管理员人工操作锁定
	public static final int userLockTypeBeenAdmin = 10;
	
	
	//普通用户允许登录次数的key
	public static final int userLoginCountKey = 1;
	
	//普通终端允许登录次数的key
	public static final int terminalLoginCountKey = 2;
	
	//允许连续失败登录次数默认值
	public static final int allowFailedLoginCount = 5;
	
	//用户登陆后的session失效时间
	public static final int userLoginFadeouteTimeSpan =  15*60*1000;
	
	/**数据表校验字段校验失败错误码***/
	public static final int UserTableVerifyFieldError = 0x501;
	public static final int PermissionTableVerifyFieldError = 0x502;
	public static final int RoleTableVerifyFieldError = 0x503;
	public static final int TerminalStatusTableVerifyFieldError = 0x504;
	public static final int LoginLogTableVerifyFieldError = 0x505;
	public static final int SafeLogTableVerifyFieldError = 0x505;
	public static final int OperLogTableVerifyFieldError = 0x505;
	
	/*-----------------------------**/
	
	/*-------------------登录相关的错误码----------------------*/
	public static final String loginResCodeKey = "status";
	
	public static final String loginResData = "msg";
	
	public static final String isModifyPassword = "modifyPass";
	
	//用户不存在
	public static final int userNotFoundError = 0x401;
	
	//密码验证错误
	public static final int passwordCheckFailedError = 0x402;
	
	//用户被锁定导致登录失败
	public static final int userLockedError = 0x403;
	
	//用户有效期失效导致登录失败
	public static final int userFadeOutError= 0x404;
	
	//密码有效期过期导致登录失败
	public static final int passwordFadeOutError = 0x405;
	
	//校验位比对失败导致登录失败
	public static final int verifyFailedError = 0x406;
	
	//登录时间段不允许
	public static final int loginTimeNotAllowError = 0x407;
	
	//登录Ip不允许
	public static final int loginIpNotAllowError = 0x408;
	
	//终端被锁定导致登录失败错误
	public static final int terminalLockError = 0x409;
	
	//用户重复多点登录错误
	public static final int multipleUserLoginError = 0x40A;
	
	//密码需要强制重新修改
	public static final int passwordNeedChangeError = 0x40B;
	
	//由于终端状态表被篡改导致登录失败
	public static final int terminalStatusNotSafeError = 0x40C;
	
	//当前在线人数已经达到最大
	public static final int currentOnlineCountMaxError = 0x40D;
	
	//账户长时间未使用导致登录错误
	public static final int userNameLongTimeNotUsedError = 0x40E;
	
	//用户登陆频率太频繁
	public static final int userLoginHighFrequencyError = 0x40F;
	
	/*---------------------------------------------------------*/
	
	//普通用户
	public static final int customerTypeNormal = 1;

	public static final String SysUser = "sys";
	
	//终端
	public static int customerTypeTerminal = 2;
	
	public static String getDescriptionByErrorCode(int code) {
		switch(code) {
			case passwordLengthError:
				return "密码长度不能少于8位！";
			case passwordNotSafeError: 
				return "密码复杂度太低！";
			case idcardLengthError :
				return "身份证长度有误！";
			case idcardCheckBitError: 
				return "身份证地区信息有误！";
			case idcardBirthdayError :
				return "身份证生日信息有误！";
			case idcardLastBitError :
				return "身份证最后一位校验码有误";
			case usernameDuplicateError: 
				return "用户名已存在";
			case employerIdDuplicateError: 
				return "员工编号已存在";
			case idcardDuplicateError:
				return "身份证号码已存在";
			case userNotFoundError:
				return "用户不存在";
			case passwordCheckFailedError:
				return "密码校验失败";
			case userLockedError:
				return "用户被锁定";
			case RoleTableVerifyFieldError:
				return "角色表被非法篡改过";
			case userFadeOutError:
				return "用户有效期已过";
			case passwordFadeOutError:
				return "密码有效期已过";
			case verifyFailedError:
				return "校验码验证失败，请确认是否有人修改过数据库";
			case loginTimeNotAllowError:
				return "当前时间不允许登录";
			case loginIpNotAllowError:
				return "当前IP不允许登录";
			case passwordNotEqualError:
				return "两次输入的密码不一致";
			case terminalLockError:
				return "此终端已经被锁定";
			case multipleUserLoginError:
				return "此用户目前已经登录，不允许重复登录";
			case passwordNeedChangeError:
				return "请修改密码后再登录";
			case terminalStatusNotSafeError:
				return "此IP的终端状态表被人为篡改";
			case userLockType_InvalidLock:
				return "此用户失效导致被锁定";
			case userLockType_FailedAuthLock:
				return "用户密码错误次数过多被锁定";
			case userLongTimeNotUseLock:
			case userNameLongTimeNotUsedError:
				return "用户长期未使用被锁定";
			case userLockTypeBeenAdmin:
				return "账号被管理员人工锁定";
			case userLockType_Lock:
				return "账号被锁定";
			case oldPasswordFailedError:
				return "原始密码校验失败";
			case userLoginHighFrequencyError:
				return "您的登陆次数过于频繁";
			default:
				return "未知错误码";
		}
	}
}
